<template>
   <div>
     <router-link to="/" tag="div" class="header-abs" v-show="showAbs">
        <div class="iconfont header-abs-back">&#xe643;</div>
     </router-link>
     <div class="header" v-show="!showAbs" :style="opacityStyle">
       <div class="header-left">
          <router-link to="/" class="iconfont back-icon" tag="div">&#xe643;</router-link>
       </div>
       <h1>东莞龙凤山庄影视渡假村</h1>
     </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {opacity}
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  unmounted () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
    @import '~styles/varibles.styl'
  .header-abs
    width .72rem
    height .72rem
    line-height .72rem
    border-radius .36rem
    background-color #000
    opacity .5
    position absolute
    top .1rem
    left .1rem
    color #fff
    text-align center
    .header-abs-back
      font-size .36rem
      font-weight 700
  .header
    z-index 2
    position fixed
    top 0
    left 0
    right 0
    line-height: $headerHeight
    background: $bgColor
    color: #fff
    .header-left
      width: .64rem
      float: left
      .back-icon
        text-align: center
        font-size: .4rem
    h1
      overflow hidden
      line-height .88rem
      margin 0 1rem
      font-size .32rem
      text-align center
</style>
